package org.jeecg.modules.kuner.viporderbase.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.kuner.viporderbase.entity.KrVipOrderBase;
import org.jeecg.modules.kuner.viporderbase.service.IKrVipOrderBaseService;
import org.jeecg.modules.kuner.viporderbase.vo.PlaceOrderVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;

/**
 * @Description: 会员订单
 * @Author: jeecg-boot
 * @Date: 2025-02-19
 * @Version: V1.0
 */
@Api(tags = "会员订单")
@RestController
@RequestMapping("/api/krVipOrderBase")
@Slf4j
public class KrVipOrderBaseApiController extends JeecgController<KrVipOrderBase, IKrVipOrderBaseService> {

    @Resource
    private IKrVipOrderBaseService orderBaseService;

    /**
     * 会员下单
     *
     * @param placeOrderVO 下单必要的参数信息
     * @return 下单结果
     */
    @PostMapping("/placeOrder")
    @ApiOperation("会员下单若之前有未支付的订单会返回之前订单")
    public Result<KrVipOrderBase> placeOrder(@RequestBody PlaceOrderVO placeOrderVO) {
        KrVipOrderBase krVipOrderBase = orderBaseService.placeOrder(placeOrderVO);
        return Result.OK("查询成功！", krVipOrderBase);
    }

    /**
     * 取消一个未支付的订单
     *
     * @param orderId 订单信息
     * @return 取消结果
     */
    @PostMapping("/cancelOrder/{orderId}")
    @ApiOperation("取消订单")
    public Result<?> cancelOrder(@PathVariable String orderId) {
        orderBaseService.cancelOrder(orderId);
        return Result.OK("取消成功！");
    }

    /**
     * 拉起支付
     *
     * @param orderId 订单信息
     * @return 拉起支付必要的参数信息
     */
    @GetMapping("/toPay/{orderId}")
    @ApiOperation("拉起支付")
    public Result<PrepayWithRequestPaymentResponse> toPay(@PathVariable String orderId) {
        PrepayWithRequestPaymentResponse prepayWithRequestPaymentResponse = orderBaseService.toPay(orderId);
        return Result.OK("查询成功！", prepayWithRequestPaymentResponse);
    }


}
